/**
 * 
 */
package com.cats.activity;

import java.util.ArrayList;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

import com.cats.R;
import com.cats.adapter.ShipmentListAdapter;
import com.cats.model.ShipmentListItemModel;

public class ShipmentListSubviewActivityRecent extends BaseActivity {
	
	private ListView shipmentListView = null;
	private ShipmentListAdapter shipmentListAdapter = null;
	private ArrayList<ShipmentListItemModel> shipmentList = null;
	
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.shipmentlist_subactivity_recent);
        System.out.println("[ShipmentListSubviewActivityRecent]:onCreate()");
        
        // Test data
        // TODO:request shipment list
        shipmentList = new ArrayList<ShipmentListItemModel>();
        shipmentList.add(new ShipmentListItemModel(0, "6789012345678901234", "11/21/2013", "2801 S University Ave, Little Rock, AR 72204, United States"));
        shipmentList.add(new ShipmentListItemModel(1, "7890123456789012345", "11/21/2013", "2801 S University Ave, Little Rock, AR 72204, United States"));
        shipmentList.add(new ShipmentListItemModel(1, "8901234567890123456", "11/20/2013", "2801 S University Ave, Little Rock, AR 72204, United States"));
        shipmentList.add(new ShipmentListItemModel(2, "9012345678901234567", "11/20/2013", "2801 S University Ave, Little Rock, AR 72204, United States"));
        shipmentList.add(new ShipmentListItemModel(2, "1012345678901234567", "11/15/2013", "2801 S University Ave, Little Rock, AR 72204, United States"));

        shipmentListAdapter = new ShipmentListAdapter(this, R.layout.shipmentlist_listview_item, shipmentList);
		shipmentListView = (ListView)findViewById(R.id.listViewRecent);
		shipmentListView.setAdapter(shipmentListAdapter);	
		
		shipmentListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				int position = arg2;

				System.out.println("[ShipmentListSubviewActivityRecent]Select " + position);
				
				String trackIdString = shipmentList.get(position).getTrackingNumber();
				System.out.println("[ShipmentListSubviewActivityRecent]Select:" + trackIdString);
				
				// navigate to addresses page
				final Intent intent = new Intent(ShipmentListSubviewActivityRecent.this, ShipmentActivity.class);
				intent.putExtra("ID", trackIdString);		
				intent.putExtra("SOURCE", "com.cats.activity.ShipmentListActivity");
				intent.putExtra("STATUS", shipmentList.get(position).getStatus());
			    startActivity(intent);
			}
		});
	}

    
    @Override
    protected void onResume() {
    	super.onResume();
    	System.out.println("[ShipmentListSubviewActivityRecent]:onResume()");
    }
}



